﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace HuangjjEF1
{
    public delegate void PrintDel(SqlDataReader Sdr);
    class Program
    {
        public static string constr = "Data Source=.;Initial Catalog=StudentDB;Integrated Security=True";
        public static void Print(string sql, PrintDel pd)
        {
            using (var conn = new SqlConnection(constr))
            {
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    var sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (sdr.Read())
                    {
                        pd.Invoke(sdr);
                    }
                }
            }
        }
    }
}
